<?php

namespace app\miniprograms\controller;

use controller\BasicAdmin;
use service\DataService;
use service\NodeService;
use service\ToolsService;
use think\App;;
use think\Db;

/**
 * 机器管理
 * Class Machine
 * @package app\admin\controller
 * @author liuda <1576283429@qq.com>
 */
class MachineTypeAction extends BasicAdmin
{
    public $table = 'machine_type_action';
    /**
     * 机器管理列表
     */
    public function index(){
        $this->title = '设备指令';
        $session = $this->request->session();
        $user = $session['user'];  //$user['is_admin']  1为管理员  其余是供应商
        $where = ' 1 ';
        $where.=" and A.is_deleted = 0 ";
        
        return parent::_list(Db::table('machine_type_action')->alias('A')->join('machine_type U','A.machine_type_id = U.id','LEFT')->field('A.id,A.action, A.machine_action,U.supplier,U.name,U.brand,U.kind')->where('A.is_deleted = 0')->order('A.id desc'));
    }

    /**
     * 添加机器
     * @return array|string
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\Exception
     */
    public function add()
    {
        $machine_type = Db::table('machine_type')->field('id,name,brand,supplier')->where('is_deleted = 0')->select(); //获取地区
        $this->assign('machine_type', $machine_type);
        return $this->_form($this->table, 'form');
    }


    /**
     * 表单数据默认处理
     * @param array $data
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function _form_filter($data)
    {
        if ($this->request->isPost()) {
            $data['machine_type_id'] = $this->request->post('machine_type_id');
        } else {

        }
    }


   /*
    * 编辑机器
    */
    public function edit()
    {
        $machine_type = Db::table('machine_type')->field('id,name,brand,supplier')->where('is_deleted = 0')->select(); //获取地区
        $this->assign('machine_type', $machine_type);
        return $this->_form($this->table, 'form');
    }


    /**
     * 删除机器
     */
    public function del(){
        if (DataService::update($this->table)) {
            $this->success("删除成功！", '');
        }
        $this->error("删除失败，请稍候再试！");
    }




}